#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

#define FOR(i,a,n) for(int i=a,_n(n);i<_n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

typedef pair<int,int> pii;

int main()
{
    int n,k;
    while(cin>>n>>k)
    {
        vector<pii> v;
        REP(i,k)
        {
            int t;
            scanf("%d",&t);
            v.push_back(pii(t,i+1));
        }
        sort(v.begin(),v.end());
        int off = v.size()<n?0:v.size()-n;
        multiset<pii,greater<pii> > s(v.begin()+off,v.end());
        //printf("s.size = %d\n",s.size());
        while(s.size()<n)
        {
            printf("s.size = %d\n",s.size());
           // cout<<endl;
            pii pt = *s.begin();
            s.erase(s.begin());
            int t = pt.first/2;
            s.insert(pii(t,pt.second));
            s.insert(pii(pt.first-t,pt.second));
        }
        while(true)
        {
            multiset<pii,greater<pii> >::iterator st = s.begin();
            multiset<pii,greater<pii> >::iterator ed = --s.end();
           // printf("st:(%d,%d) ed(%d,%d)\n",st->first,st->second,ed->first,ed->second);
            if(st->first/2>ed->first)
            {
                pii pt = *st;
                int t = st->first/2;
                s.erase(ed);
                s.erase(s.begin());
                s.insert(pii(t,pt.second));
                s.insert(pii(pt.first-t,pt.second));
            }
            else break;
        }
        v.clear();
        multiset<pii,greater<pii> >::iterator it;
        for(it=s.begin();it!=s.end();++it)
        {
          //  printf("(%d,%d)\n",it->first,it->second);
            v.push_back(*it);
            swap(v.back().first,v.back().second);
        }
        int pos = v.back().first;
        int ansMax = 0,i;
        for(i=v.size()-1;i>=0&&v[i].first==pos;--i) ansMax += v[i].second;
        ansMax/=v.size()-i-1;
        sort(v.begin(),v.end());
        printf("%d\n",ansMax);
        REP(i,n)
        {
            printf("%d\n",v[i].first);
        }
    }
	return 0;
}
